@extends('layouts.admin.master')

@section('content')
    @include('kindeditor.head')
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <br/>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->

        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        添加文章
                    </div>
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        @include('admin.common.errors')
                        <form class="form-horizontal" role="form" method="post"
                              action="{{ route('admin.articles.store') }}">
                            {{ csrf_field() }}
                            <div class="form-group">
                                <label for="inputTitle" class="col-sm-2 control-label">文章标题</label>

                                <div class="col-sm-4">
                                    <input type="text" name="title" class="form-control" id="inputTitle"
                                           value="{{ old('title') }}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="selectCategoryId" class="col-sm-2 control-label">文章分类</label>

                                <div class="col-sm-4">
                                    <select id="selectCategoryId" name="article_category_id" class="form-control">
                                        @foreach($articleCategories as $articleCategory)
                                            @if($articleCategory->parent_id == '0')
                                                <optgroup label="{{ $articleCategory->name }}">
                                                    @foreach($articleCategories as $v)
                                                        @if($v->parent_id == $articleCategory->id)
                                                            <option value="{{ $v->id }}" {{ old('article_category_id') == $v->id? 'selected="selected"':'' }}>{{ $v->name }}</option>
                                                        @endif
                                                    @endforeach
                                                </optgroup>
                                            @endif
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="txtContent" class="col-sm-2 control-label">文章内容</label>

                                <div class="col-sm-10">
                                    <textarea id="txtContent" name="content">{{ old('content') }}</textarea>
                                    <script type="text/javascript">
                                        KindEditor.ready(function (K) {
                                            K.create('textarea[name="content"]', {
                                                width: '800px',
                                                height: '400px',
                                                afterBlur: function(){this.sync();},
                                                extraFileUploadParams: {_token: '{{ csrf_token() }}'},
                                                uploadJson: '{{ route('kindeditor.store') }}',
                                                resizeType: 1,
                                                items: [
                                                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                                                    'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                                                    'insertunorderedlist', '|', 'emoticons', 'image', 'link']
                                            });
                                        });
                                    </script>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-10">
                                    <button type="submit" class="btn btn-default">确认</button>
                                </div>
                            </div>
                        </form>
                        <!-- /.form-horizontal -->
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
    </div>
@endsection